using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ShootThemUp.Sources.GameElements.Ships.Player
{
    /// <summary>
    /// This class represents the explosion of the ship
    /// </summary>
    public class Explosion : MovableSprite
    {
        #region Spritesheet Constants Fields

        /// <summary>
        /// The X position of the player ship texture in the spritesheet (in px).
        /// </summary>
        private const int SPRITESHEET_POSITION_X = 0;
        /// <summary>
        /// The Y position of the player ship texture in the spritesheet (in px).
        /// </summary>
        private const int SPRITESHEET_POSITION_Y = 0;
        /// <summary>
        /// The width of the player ship texture in the spritesheet (in px).
        /// </summary>
        private const int SPRITESHEET_WIDTH = 64;
        /// <summary>
        /// The height of the player ship texture in the spritesheet (in px).
        /// </summary>
        private const int SPRITESHEET_HEIGHT = 64;
        /// <summary>
        /// The number of sprites used to animate the ship.
        /// </summary>
        private const int NUMBER_OF_FRAME = 16;
        /// <summary>
        /// The duration of a frame of the animation.
        /// </summary>
        private const float ANIMATION_DURATION = 0.01f;

        #endregion

        #region Fields

        private float index = 0;

        #endregion

        #region Initialization


        /// <summary>
        /// Initializes a new instance of the <see cref="Explosion"/> class.
        /// </summary>
        /// <param name="x">The x-position.</param>
        /// <param name="y">The y-position</param>
        public Explosion(int x, int y)
        {
            // Default position of the explosion
            this.Position = new Vector2(x, y);

            // The rectangle which will be use to select the texture of the explosion
            this.SourceRectangle = new Rectangle(Explosion.SPRITESHEET_POSITION_X, Explosion.SPRITESHEET_POSITION_Y, Explosion.SPRITESHEET_WIDTH, Explosion.SPRITESHEET_HEIGHT);
        }

        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content, string assetName)
        {
            base.LoadContent(content, assetName);
        }

        #endregion

        #region Update & Draw

        /// <summary>
        /// Updates the sprite position in function of the specified game time.
        /// </summary>
        /// <param name="gameTime">A snapshot of the current time.</param>
        public override void Update(GameTime gameTime)
        {
            #region Animation of the Texture

            this.index += gameTime.ElapsedGameTime.Milliseconds * Explosion.ANIMATION_DURATION;

            if (this.index < Explosion.NUMBER_OF_FRAME)
                this.SourceRectangle = new Rectangle(Explosion.SPRITESHEET_POSITION_X + (int)index * Explosion.SPRITESHEET_WIDTH, Explosion.SPRITESHEET_POSITION_Y, Explosion.SPRITESHEET_WIDTH, Explosion.SPRITESHEET_HEIGHT);
            base.Update(gameTime);

            #endregion
        }

        /// <summary>
        /// Draws this sprite in the specified sprite batch.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
        }

        #endregion
    }
}
